package com.uhu.code;

import com.uhu.code.help.ListNode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 142.环形链表II todo
 * https://leetcode.cn/problems/linked-list-cycle-ii/?envType=study-plan-v2&envId=top-100-liked
 */
public class Solution142 {
    public ListNode detectCycle(ListNode head) {
        ListNode temp = head;
        Set<ListNode> ln = new HashSet<>();
        while(temp != null) {
            if(ln.contains(temp)) {
                return temp;
            }else {
                ln.add(temp);
            }
            temp = temp.next;
        }
        return null;
    }
}
